import 'package:flutter/material.dart';
import 'package:rongcloud_im_wrapper_plugin/rongcloud_im_wrapper_plugin.dart';

import '../models/bt_chat_model.dart';
import 'bt_chat_message_file_widget.dart';
import 'bt_chat_message_image_widget.dart';
import 'bt_chat_message_text_widget.dart';
import 'bt_chat_message_voice_widget.dart';

class BtChatMessageListWidget extends StatelessWidget {
  const BtChatMessageListWidget({super.key, required this.model});

  final BtChatModel model;

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      reverse: true,
      shrinkWrap: false,
      controller: model.scrollController,
      itemBuilder: (context, index) {
        var item = model.messageList[index];
        if (item.message is RCIMIWTextMessage) {
          return BtChatMessageTextWidget(item: item, model: model);
        } else if (item.message is RCIMIWVoiceMessage) {
          return BtChatMessageVoiceWidget(item: item, model: model);
        } else if (item.message is RCIMIWImageMessage) {
          return BtChatMessageImageWidget(item: item, model: model);
        } else if (item.message is RCIMIWFileMessage) {
          return BtChatMessageFileWidget(item: item, model: model);
        } else {
          return const Text("Unknown message type");
        }
        // switch (item.message?.messageType) {
        //   case RCIMIWMessageType.text:
        //     return BtChatMessageTextWidget(item: item, model: model);
        //   case RCIMIWMessageType.voice:
        //     return BtChatMessageVoiceWidget(item: item, model: model);
        //   case RCIMIWMessageType.image:
        //     return BtChatMessageImageWidget(item: item, model: model);
        //   case RCIMIWMessageType.file:
        //     return BtChatMessageFileWidget(item: item, model: model);
        //   default:
        //     return const Text("Other message");
        // }
      },
      itemCount: model.messageList.length,
    );
  }
}
